<template>
    <div class="login">

        <h2 style="padding-left: 25px">用户登录</h2>
        <div class="form">
            <!--登录表单-->
            <el-form :label-position="labelPosition" label-width="65px" :model="formLabelAlign" size="medium">
                <el-form-item label="账号">
                    <el-input v-model="formLabelAlign.name"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input v-model="formLabelAlign.region"></el-input>
                </el-form-item>
            </el-form>
            <div class="btn">
                <el-button type="primary" @click="login">登录</el-button>
                <el-button type="success" @click="register">注册</el-button>
            </div>
            <span>请选择登录身份:</span>
            <el-radio v-model="radio" label="1">咨询师</el-radio>
            <el-radio v-model="radio" label="2">管理员</el-radio>

        </div>


    </div>
</template>

<script>
    export default {
        name: "Login",
        data() {
            return {
                labelPosition: 'right',
                formLabelAlign: {
                    name: '',
                    region: '',
                    type: ''
                },
                radio: '1'
            };
        },
        methods:{
            navigateToPage() {
                this.$router.push('/index');
            },
            clogin(){
                console.log("bbbbbb")
                console.log(this.formLabelAlign.name)
                this.axios.get("http://localhost:8080/consultant/login",{
                    params:{
                        cname:this.formLabelAlign.name,
                        cpassword:this.formLabelAlign.region
                    }
                }).then(res=>{
                    console.log("bcvbbbcbcb")
                    console.log(res.data)
                    if (res.data.data==1){
                        this.$message({
                            message: '登录成功',
                            type: 'success'
                        });
                        this.navigateToPage();
                    }else if (res.data.data==0){
                        this.$message({
                            message: '用户不存在',
                            type: 'warning'
                        });
                    }else if (res.data.data==-1){
                        this.$message({
                            message: '密码错误',
                            type: 'warning'
                        });
                    }
                })
            },
            mlogin(){
                console.log("bbbbbb")
                console.log(this.formLabelAlign.name)
                this.axios.get("http://localhost:8080/manger/mlogin",{
                    params:{
                        mname:this.formLabelAlign.name,
                        mpassword:this.formLabelAlign.region
                    }
                }).then(res=>{
                    console.log("bcvbbbcbcb")
                    console.log(res.data)
                    if (res.data.data==1){
                        this.$message({
                            message: '登录成功',
                            type: 'success'
                        });
                        this.$router.push('/manger');
                    }else if (res.data.data==0){
                        this.$message({
                            message: '用户不存在',
                            type: 'warning'
                        });
                    }else if (res.data.data==-1){
                        this.$message({
                            message: '密码错误',
                            type: 'warning'
                        });
                    }
                })
            },
            login(){
              if (this.radio==1){
                  this.clogin()
              }else {
                  this.mlogin()
              }
            },
            register(){
                this.$router.push('/register');
            }
        }
    }
</script>

<style scoped>
    *{
        margin: 0;
        padding: 0;
    }
    .login{
        text-align: center;
        padding-top: 14%;
        padding-bottom: 22%;
        background-image: url("https://gd-hbimg.huaban.com/559f622332cb30c783488a1cb74ee5fb229007f263521-IwSnHF_fw1200");
        background-size: 100%;
    }
    .form{
        width: 450px;
        /*background-color: #66ccff;*/
        margin: 0 auto;
    }
    .btn{
        padding-left: 30px;
        margin-bottom: 20px;
    }
    span{
        margin: 20px;
    }
</style>